﻿using Blazor.Diagrams.Core.Geometry;
using Blazor.Diagrams.Core.Models;
using Blazor.Diagrams.Core.Models.Base;
using ERP.Workflow.Designer.BlazorUI.Core;
using ERP.Workflow.Designer.BlazorUI.Domain;
using ERP.Workflow.Designer.Domain.Shared;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Data;

namespace ERP.Workflow.Designer.BlazorUI.Models
{

    public class FlowNode : NodeModel, IEditableModel
    {
       
        public FlowNode()
        {
           
           // AddPorts();
        }

        public FlowNode(Point? position = null)
        : base(position)
        {
           // AddPorts();
        }
        public FlowNode(Point? position = null, RenderLayer layer = RenderLayer.HTML,
       ShapeDefiner? shape = null) : base(position, layer, shape)
        {
          //  AddPorts();
        }
        public FlowNode(string id, Point? position = null, RenderLayer layer = RenderLayer.HTML, ShapeDefiner? shape = null)
             :base(id, position, layer,shape)
        {
           // AddPorts();
        }


        protected void AddPorts()
        {
            base.AddPort(new FlowPortModel(this, PortAlignment.Bottom, null, new Size(10, 10)));
            base.AddPort(new FlowPortModel(this, PortAlignment.Top, null, new Size(10, 10)));
            base.AddPort(new FlowPortModel(this, PortAlignment.Left, null, new Size(10, 10)));
            base.AddPort(new FlowPortModel(this, PortAlignment.Right, null, new Size(10, 10)));
        }
        public event Action<FlowNode, string, string> OnTitleChange;

        /// <summary>
        /// 是否可编辑节点
        /// </summary>
        public bool Contenteditable { get; set; } = false;
        /// <summary>
        /// 节点名称
        /// </summary>
        public new string Title
        {
            get { return base.Title ?? "步骤名称"; }
            set
            {
                if (value != base.Title)
                {
                    OnTitleChange?.Invoke(this, base.Title, value);
                }
                base.Title = value;
            }
        }
        /// <summary>
        /// 节点图标
        /// </summary>
        public string Icon { get; set; }
        /// <summary>
        /// 图标旋转角度
        /// </summary>
        public int Rotate { get; set; }
        /// <summary>
        /// x坐标
        /// </summary>
        public Double X => Position.X;
        /// <summary>
        /// y坐标
        /// </summary>
        public Double Y => Position.Y;

        public string? Name { get; set; }

        public string? Code { get; set; }
        /// <summary>
        /// 序号
        /// </summary>

        public int? OrderNo { get; set; }

        /// <summary>
        /// 节点类型
        /// </summary>
        public NodeType NodeType { get; set; } = NodeType.General;

        /// <summary>
        /// 发散规则
        /// </summary>

        public SplitRule SplitRule { get; set; } = SplitRule.SplitOR;

        /// <summary>
        /// 聚合规则
        /// </summary>
        public JoinRule JoinRule { get; set; } = JoinRule.SplitXOR;
        /// <summary>
        /// 响应类型
        /// </summary>
        public ReposeType ReposeType { get; set; } = ReposeType.Any;

        /// <summary>
        /// 进入类型
        /// </summary>
        public EntyType EntyType { get; set; } = EntyType.Auto;

        /// <summary>
        /// 发出类型
        /// </summary>
        public ExitType ExitType { get; set; } = ExitType.Manual;

        /// <summary>
        /// 参与者实现类
        /// </summary>
        public string? ActorAssembly { get; set; }


        /// <summary>
        /// 是否可改变参与者
        /// </summary>
        public bool IsCanChangeActor { get; set; } = false;

        /// <summary>
        /// 传阅人实现类
        /// </summary>
        public string? CirculatedAssembly { get; set; }

        /// <summary>
        /// 是否可改变传阅人
        /// </summary>
        public bool IsCanChangeCirculated { get; set; } = false;

        /// <summary>
        /// 表单是否可编辑
        /// </summary>
        public bool IsCanEditForm { get; set; } = false;

        /// <summary>
        /// 待办处理模式
        /// </summary>
        public ModeType ModeType { get; set; } = ModeType.PC;

        /// <summary>
        /// 历史处理过跳过本次处理
        /// </summary>
        public bool HasHistoryCanSkip { get; set; }

        /// <summary>
        /// 没有参与者，跳过本次处理
        /// </summary>
        public bool NotActorIsCanSkip { get; set; } = false;

        /// <summary>
        /// 没有参与者的默认参与人
        /// </summary>
        public string? NotActorDefault { get; set; }



        /// <summary>
        /// 是否显示转交按钮
        /// </summary>
        public bool IsCanTransfer { get; set; } = false;

        /// <summary>
        /// 能否改变转交人
        /// </summary>
        public bool IsCanChangeTransfer { get; set; } = false;


        /// <summary>
        /// 是否显示传阅按钮
        /// </summary>
        public bool IsCanCirculated { get; set; } = false;
        /// <summary>
        /// 是否可评论
        /// </summary>
        public bool IsCanComments { get; set; } = false;
        /// <summary>
        /// 是否可驳回
        /// </summary>
        public bool IsCanRejected { get; set; } = false;
        /// <summary>
        /// 是否可撤回
        /// </summary>
        public bool IsCanWithdraw { get; set; } = false;

        /// <summary>
        /// 是否可以加签
        /// </summary>
        public bool IsAppend { get; set; }

        /// <summary>
        /// 催办
        /// </summary>
       public bool IsCanRush { get; set; }   

        /// <summary>
        /// 是否自由流程
        /// </summary>
        public bool IsFree { get; set; }



    }


}
